#include <stdio.h>
#include <stdlib.h>

#define true 1
#define false 0
typedef unsigned char bool;

#define MaxSize 10
typedef struct{
    int data[MaxSize];
    int length;
}SqList;

void InitList(SqList *L){
    for(int i=0; i<MaxSize; i++){
        L->data[i] = 0; //将所有数据元素设置为默认值
    }
    L->length = 0;      //顺序表初始长度为0
}

bool ListInsert(SqList *L,int num,int e){
    if(num<1||num>L->length+1){
        printf("parameter num error,num<1 or num>L->length+1\n");
        return false;
    }
    if(L->length>=MaxSize){
        printf("List is full,can't insert.\n");
        return false;
    }
    printf("i-1\t\ti\n");
    for(int i=L->length; i>=num;i--){
        L->data[i] = L->data[i-1];      //将
        printf("%d\t->\t%d\n",i-1,i);
    }
    L->data[num-1] = e;                 //这里比如说要在第3个元素插入,那么应该将数赋值给data[2]
    printf("data[num-1] = %d\n",L->data[num-1]);
    return true;
}

int main(){
    SqList L;
    InitList(&L);
    printf("insert some values:111 data[0]~data[5]\n");
    for (int i = 0;i<=5;i++){
        L.data[i] = 111;
    }
    L.length = 6;
    for (int i = 0;i<=L.length;i++){
        printf("data[%d] = %d\n",i,L.data[i]);
    }
    ListInsert(&L, 3, 666);
    for (int i = 0;i<=L.length;i++){
        printf("data[%d] = %d\n",i,L.data[i]);
    }
    return 0;
}
